from django.db import models
from tower.models import *
from supplier.models import *

#资产
class Asset(models.Model):
    
    asset_name = models.CharField(max_length = 200,unique = True)#资产名
    price = models.FloatField()#单价
    
#中转站
class Interchange(models.Model):
    '''
        仅仅记录每个房间的资产
    '''
    # 关联tower里的房间
    room = models.ForeignKey(Room,on_delete = models.CASCADE)
    # 关联asset里的资产
    asset = models.ForeignKey(Asset,on_delete = models.CASCADE)
    #关联supplier里的厂家
    vender = models.ForeignKey(Vender,on_delete = models.CASCADE,null = True,blank = True)
    asset_num = models.IntegerField(default = 0)
#需要修理的数量
class Repair(models.Model):
    '''
        资产状态为需要修理
    '''
    #关联中转站
    interchange = models.ForeignKey(Interchange,on_delete=models.CASCADE)
    repair_num = models.IntegerField(default = 0) 


#损坏数量
class Damage(models.Model):
    '''
        资产状态为损坏
    '''
    #关联中转站
    interchange = models.ForeignKey(Interchange,on_delete=models.CASCADE)
    damage_num = models.IntegerField(default = 0) 


#采购
class Purchase(models.Model):
    '''
        采购
        关联房间--需要前端传入楼号楼层
        lr = 录入
        pur = 采购
        room = 存入地点
    '''
    #关联tower里的房间
    save_room = models.ForeignKey(Room,on_delete = models.CASCADE)#存入地址room_num
    #关联login里的用户
    user = models.ForeignKey(User,on_delete = models.CASCADE)#采购人user_name
    #关联asset里的资产
    asset_name = models.ForeignKey(Asset,on_delete=models.CASCADE)
    pur_num = models.IntegerField() 
    lr_date = models.DateTimeField(auto_now_add = True)
    
    
    










